/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Servlet.medic;

import Entities.Medico;
import Logger.MyLogger;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author marcy
 */
public class WelcomeMedic extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        MyLogger.getLogger().debug("Servlet di welcome per i medici");
        
        Medico medico = (Medico) request.getSession().getAttribute("Medico");
        if (medico == null) {
            medico = new Medico();
        }
        String rootpath = request.getContextPath();

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            //Sezione CSS
            out.println("<link href='http://fonts.googleapis.com/css?family=Quicksand:300,400' rel='stylesheet' type='text/css' />");
            out.println("<link href='" + rootpath + "/css/smoothness/jquery-ui-1.8.16.custom.css' rel='stylesheet' type='text/css' />");
            out.println("<link href='" + rootpath + "/css/stile.css' rel='stylesheet' type='text/css' />");
            //Sezione javascript
            out.println("<script src=\"" + rootpath + "/js/jquery-1.6.2.min.js\" ></script>");
            out.println("<script src=\"" + rootpath + "/js/jquery-ui-1.8.16.custom.min.js\" ></script>");
            out.println("<title>" + medico.getNome() + " " + medico.getCognome() + "</title>");
            out.println("</head>");
            out.println("<body>");
            out.println(
                      "<div id='cont'>"
                    + "<header>"
                    + "Bentornato " + medico.getNome() + " " + medico.getCognome()
                    + "</header>"
                    + "<nav>"
                    + "<div id='menu'>"
                    + "<h3><a href='#'>Pazienti</a></h3>"
                    + "<div>"
                    + "<a href=\"javascript: loadContent('article','Richiamo'); \">Richiama Pazienti</a><br/>"
                    + "<a href=\"javascript: loadContent('article','Richiamati'); \">Visualizza pazienti richiamati</a>"
                    + "</div>"
                    + "<h3><a href='#'>Account</a></h3>"
                    + "<div>"
                    + "<a href='"+request.getContextPath()+"/logout'>Logout</a>"
                    + "</div>"
                    + "<h3><a href='#'>Lista file richiami</a></h3>"
                    + "<div id='pdf'>"
                    + "<!-- Il file viene richiamato ad ogni accesso della pagina tramite ajax -->"
                    + "</div>"
                    + "</div>"
                    + "</nav>"
                    + "<article>"
                    + "<h3>Informazioni</h3>"
                    + "Da questa pagina è possibile accedere a tutti i servizi offerti dal portale riservati ai medici.<br/>"
                    + "A sinistra trovate il menu.<br/>"
                    + "Sotto la voce pazienti potete compiere due azioni:"
                    + "<ul>"
                    + "<li>Richiamare i pazienti per una vaccinazione</li>"
                    + "<li>Visualizzare le vaccinazioni create in un arco di tempo arbitrario</li>"
                    + "</ul>"
                    + "In account potete effettuare il Logout<br/>"
                    + "E attraverso l'ultima voce potete vedere l'ultima lista dei richiami creata dai vostri colleghi.<br/>"
                    + "</article>"
                    + "</div>"
                    + "<script>"
                    + "$('#menu').accordion();"
                    + "function loadContent(elemento, contenuti){"
                    + "$.ajax({"
                    + "url: contenuti,"
                    + "success: function (data){"
                    + "$(elemento).html(data);"
                    + "}"
                    + "});"
                    + "}"
                    + "loadContent('#pdf','ottieniPdf');"
                    + "</script>");
            out.println("</body>");
            out.println("</html>");

        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
